<?php

namespace app\models;

use app\models\events\UploadEvent;
use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
/**
 * This is the model class for table "album".
 *
 * @property integer $id
 * @property string $name
 * @property string $type
 * @property string $description
 * @property string $brief_desc
 * @property string $pic_url
 * @property string $company
 * @property integer $publish_at
 * @property integer $created_at
 * @property integer $updated_at
 * @property integer $artist_id
 */
class Album extends ActiveRecord
{
    use DropDownListTrait;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'album';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'type', 'description', 'brief_desc', 'pic_url', 'company', 'publish_at', 'artist_id'], 'required'],
            ['publish_at', 'date', 'format' => 'php:Y-m-d G:i', 'timestampAttribute' => 'publish_at'],
            [['artist_id'], 'integer'],
            [['name', 'type', 'description', 'brief_desc', 'pic_url', 'company'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', '11'),
            'name' => Yii::t('app', '名称'),
            'type' => Yii::t('app', '类型'),
            'description' => Yii::t('app', '描述'),
            'brief_desc' => Yii::t('app', '简单介绍'),
            'pic_url' => Yii::t('app', '图片地址'),
            'company' => Yii::t('app', '唱片公司'),
            'publish_at' => Yii::t('app', '发布时间'),
            'created_at' => Yii::t('app', '创建时间'),
            'updated_at' => Yii::t('app', '修改时间'),
            'artist_id' => Yii::t('app', '主要作者id'),
        ];
    }

    /**
     * @inheritdoc
     * @return ArtistQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new ArtistQuery(get_called_class());
    }

    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'attributes'=>[
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],
            [
                'class'=>UploadEvent::className(),
                'changeAttribute'=>'pic_url',
            ]
        ];
    }
}
